package com.example.shushiyunsst.fragment.main.home.child.fu_li_pool.sub

import android.os.Bundle
import android.view.View
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.example.library_common.base.BaseFragmentEx
import com.example.library_common.global.AppGlobals
import com.example.shushiyunsst.R
import com.google.android.material.tabs.TabLayout

/**
 * 历史福利
 * */
class LiShiFuLiFragment :BaseFragmentEx() {

    companion object{
        fun newInstance(): LiShiFuLiFragment {
            val args = Bundle()
            val fragment = LiShiFuLiFragment()
            fragment.arguments = args
            return fragment
        }
    }

    private lateinit var mTabLayout: TabLayout

    private lateinit var mViewPager: ViewPager

    private val subPages= arrayOf(
        SubLiShiFuLiFragment.newInstance(R.string.weekly_feng_hong),
        SubLiShiFuLiFragment.newInstance(R.string.month_feng_hong),
        SubLiShiFuLiFragment.newInstance(R.string.season__feng_hong),
        SubLiShiFuLiFragment.newInstance(R.string.year_feng_hong),
//        SubLiShiFuLiFragment.newInstance(R.string.glob_feng_hong)
    )

    override fun getLayoutId()= R.layout.li_shi_fu_li_fragment

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        view.findViewById<View>(R.id.mToolbar)
            .setOnClickListener { onBackPressedSupport() }

        mTabLayout=view.findViewById(R.id.mTabLayout)
        mViewPager=view.findViewById(R.id.mViewPager)

        mViewPager.adapter=object :FragmentStatePagerAdapter(
            childFragmentManager,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT){
            override fun getCount()=subPages.size

            override fun getItem(position: Int)=subPages[position]

            override fun getPageTitle(position: Int): CharSequence? {
                val item = getItem(position)
                return AppGlobals.getApplication().getString(item.labInfo)
            }

        }
        mTabLayout.setupWithViewPager(mViewPager)
    }

    override fun onBackPressedSupport(): Boolean {
        pop()
        return true
    }
}